import java.awt.Color;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.WindowConstants;

public class CalculatorWindow extends JFrame {

	private static final long serialVersionUID = -3404752928517785341L;

	Dimension currentScreenDimension;
	int refScreenWidth = 1280;
	int refScreenHeight = 800;
	int windowWidth;
	int windowHeight;

	private CalculatorPanel panel;

	public CalculatorWindow() {
		pack();
		Insets insets = getInsets();
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		currentScreenDimension = Toolkit.getDefaultToolkit().getScreenSize();
		windowWidth = getScaledWidth(400);
		windowHeight = getScaledHeight(500+insets.top);
		setBackground(Color.DARK_GRAY);
		setTitle("Casyo");
		
		setBounds((int) currentScreenDimension.getWidth()/2 - (windowWidth / 2),
				(int) currentScreenDimension.getHeight()/2 - (windowHeight / 2),
				windowWidth, windowHeight);
		setPreferredSize(new Dimension(windowWidth, windowHeight));
		
		
		addCalculatorPanel();
		pack();
		setResizable(false);
		setVisible(true);
		applyLookAndFeel();
	}
	
	
	public void addCalculatorPanel(){
		
		panel =  new CalculatorPanel(getScaledWidth(400),getScaledHeight(500));
		add(panel);
	}

	public int getScaledWidth(int width) {
		return (int) ((width * currentScreenDimension.getWidth()) / refScreenWidth);
	}

	public int getScaledHeight(int height) {
		return (int) ((height * currentScreenDimension.getHeight()) / refScreenHeight);
	}
	
	public void setValueToScreen(int value){
		panel.setScreenValue(value);
	}
	
	public void applyLookAndFeel(){
		try {
			UIManager.setLookAndFeel(
			     UIManager.getSystemLookAndFeelClassName());
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
